#include "Common.hpp"
#include "Http.hpp"
#include "Log.hpp"
#include <cstdlib>
#include <memory>
#include <mutex>
#include <string>
void Login(HttpRequest& req, HttpResponse& resp) {
    LOG(LogLevel::DEBUG) << req.Args() << ", 我们进入了处理数据的阶段！";
    std::string text = "hello" + req.Args();
    resp.SetCode(200);
    resp.SetText(text);
    resp.SetHeader("Content-Type", "text/plain");
    resp.SetHeader("Content-Length", std::to_string(text.size()));
}
void Register(HttpRequest& req, HttpResponse& resp) {
    LOG(LogLevel::DEBUG) << req.Args() << ", 我们进入了处理数据的阶段！";
    std::string text = "hello" + req.Args();
    resp.SetCode(200);
    resp.SetText(text);
    resp.SetHeader("Content-Type", "text/plain");
    resp.SetHeader("Content-Length", std::to_string(text.size()));
}
void VipCheck(HttpRequest& req, HttpResponse& resp) {
    LOG(LogLevel::DEBUG) << req.Args() << ", 我们进入了处理数据的阶段！";
    std::string text = "hello" + req.Args();
    resp.SetCode(200);
    resp.SetText(text);
    resp.SetHeader("Content-Type", "text/plain");
    resp.SetHeader("Content-Length", std::to_string(text.size()));
}
int main(int argc, char* argv[]) {
    if(argc != 2) {
        std::cout << "The usage is " << argv[0] << " + port" << std::endl;
        exit(USAGE_ERR);
    }
    uint16_t port = stoi(argv[1]);
    std::unique_ptr<Http> ser = std::make_unique<Http>(port);
    ser->RegisterService("/login", Login);
    ser->RegisterService("/register", Register);
    ser->RegisterService("/vip_check", VipCheck);
    ser->Start();
    return 0;
}